package com.csdj.dao.impl;

import com.csdj.dao.BaseDao;
import com.csdj.dao.DeptDao;
import com.csdj.entity.Department;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * packageName com.csdj.dao.impl
 *
 * @author winver
 * @version 1.0
 * @InterfaceName DeptDaoImpl
 * @date 2024/11/27
 * @description TODO
 */
public class DeptDaoImpl extends BaseDao implements DeptDao {
    @Override
    public List<Department> getAllDept() {
        //1.返回对象
        List<Department> deptList = new ArrayList<>();
        //2.获取连接
        this.conn = this.getConnection();
        //3.sql语句
        String sql = "select dept.depteid,dept.`name`,dept.manager_sn from sys_department dept";
        try {
            //4.预编译
            this.psmt = this.conn.prepareStatement(sql);
            //5.占位符  设置参数
            //6.执行sql  结果集处理
            this.rs = this.psmt.executeQuery();
            while(rs.next()){
                Department department = new Department(rs.getInt(1),
                        rs.getString(2),
                        rs.getInt(3));
                //放放集合
                deptList.add(department);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //释放资源
        }
        //7.响应返回

        return deptList;
    }
}
